const { isLogin, request} = getApp();

Page({

  /**
   * 页面的初始数据d
   */
  data: {
    show: false,
    cates: [],
    blogCates: [],
    content: ''
  },
  fetchCates(){
    request('/cms/category/list').then(res => {
      if(res.data.code === 0) {
        const cates = [];
        res.data.data.forEach(cate => {
          cates.push(cate.name)
        })
       
        this.setData({
          cates,
          blogCates: res.data.data
        })
      }
    })
  },
  onConfirm(e){
    console.log(e);
    this.onClose();
  },
  onClose(){
    this.setData({
      show: false
    })
  },
  showPop(){
    this.setData({
      show: true
    })
  },
  getHtml(e){
    /* this.setData({
      content: e.detail
    }) */
  },
  insertImage(){
    // 先选择图片  wx.chooseImage()
    wx.chooseMedia({
      count: 1,
      mediaType: ['image'],
      success: res=> {
        // 上传图片
        wx.uploadFile({
          url: 'https://api.it120.cc/conner/dfs/upload/file',
          filePath: res.tempFiles[0].tempFilePath,
          name: 'upfile',
          success: res => {
            console.log();
            const ret = JSON.parse(res.data);
            if(ret.code === 0) {
              wx.showToast({
                title: '图片插入成功',
              })
            
              this.selectComponent('#qf_editor').insertSrc(ret.data.url);
            }
          }
        })
      }
    })
  },
  onLoad(options) {
    this.fetchCates();
  },

  onShow(){
    // if(!isLogin()){
    //   // 跳转到登录页
    //   wx.navigateTo({
    //     url: '/pages/login/login'
    //   })
    // }
  }
})